package size;

import com.carrotsearch.sizeof.RamUsageEstimator;

import java.math.BigDecimal;

public class ObjectSize {

    public static void main(String[] args) {

        printSizeOf(new Object(),"new Object(): %d");
        printSizeOf(new Integer(10000),"new Integer(10000): %d");
        printSizeOf(new Double(10000d),"new Double(10000d): %d");
        printSizeOf(new Byte((byte)120),"new Byte((byte)120): %d");
        printSizeOf(new byte[100],"new byte[100]: %d");
        printSizeOf(new Byte[100],"new Byte[100]: %d");
        printSizeOf(new int[100],"new int[100]: %d");
        printSizeOf(new Integer[100],"new Integer[100]: %d");
        printSizeOf(new double[100],"new double[100]: %d");
        printSizeOf(new BigDecimal(1000000L),"new BigDecimal(1000000L): %d");
        printSizeOf("a","a: %d");
        printSizeOf("abc123","abc123: %d");
        printSizeOf(new User(),"new User(): %d");
        printSizeOf(new User1(),"new User1(): %d");
        printSizeOf(new AUser(),"new AUser(): %d");
    }

    public static void printSizeOf(Object o, String message) {
        System.out.println(String.format(message,RamUsageEstimator.sizeOf(o)));
    }
    public static class User {
        int id = 1;
    }

    public static class User1 {
        int id = 1;
        Integer code = 100;
        String name = "KK";
    }

    public static class AUser {
        int id = 10;
        User a = new User();
    }

}
